package com.yao2san.simcasserver.processor;

import lombok.Getter;
import lombok.Setter;

import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Result implements AuthenticationResult {

    private AuthenticationObject authenticationObject;
    @Setter
    private boolean success;
    @Getter
    @Setter
    private Principal principal;

    private List<String> errors;

    private Map<String, Object> attributes;

    @Getter
    private Map<String, Object> queryResultMap;

    public Result() {
        this.errors = new ArrayList<>();
        this.principal = new AttributePrincipal();
        this.authenticationObject = new DefaultAuthenticationObject();
        this.queryResultMap = new HashMap<>();
        this.attributes = new HashMap<>();
    }

    @Override
    public AuthenticationObject getAuthenticationObject() {
        return this.authenticationObject;
    }

    @Override
    public Map<String, Object> getAttributes() {
        return this.attributes;
    }

    public void setAttributes(Map<String, Object> attributes) {
        if (attributes != null)
            this.attributes.putAll(attributes);
    }

    @Override
    public Map<String, Object> getQueryResultMap() {
        return this.queryResultMap;
    }

/*    private void setPrincipal() {
        this.principal = new AttributePrincipal();
        AttributePrincipal attributePrincipal = new AttributePrincipal();
        attributePrincipal.setName(username);
        this.principal = attributePrincipal;
    }*/

    public Principal getPrincipal() {
        return this.principal;
    }

    @Override
    public boolean isSuccess() {
        return this.success;
    }

    @Override
    public List<String> getErrors() {
        return this.errors;
    }

}
